package processes.nMCounterProcess;

import os.MiniOS;
import os.MiniProcess;
import os.MiniThread;

public class MMonitorThread extends MiniThread
{
	private Counter counter;
	private Buffer buffer;

	public MMonitorThread(MiniProcess process, String tid)
	{
		super(process, tid);
	}

	@Override
	public void passThreadArguments(Object[] arguments)
	{
		buffer = (Buffer) arguments[0];
		counter = (Counter) arguments[1];
	}

	@Override
	public void run()
	{
		while (! buffer.shouldTerminateMonitor())
		{
			isExcecutionStopped();
			int val = counter.read();
			System.out.println("Value read = " + val);
			isExcecutionStopped();
			MiniOS.getInstance().outputRequest(this, "Value read = " + val);
			isExcecutionStopped();
			buffer.write(val);
		}
		isExcecutionStopped();
		MiniOS.getInstance().terminateThread(this);
	}
}